﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Data;

#endregion

namespace BesAsm.MasterData.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="CrossSectionDatumProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class CrossSectionDatumProviderBaseCore : EntityProviderBase<BesAsm.MasterData.Entities.CrossSectionDatum, BesAsm.MasterData.Entities.CrossSectionDatumKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, BesAsm.MasterData.Entities.CrossSectionDatumKey key)
		{
			return Delete(transactionManager, key.CrossSectionDataId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_crossSectionDataId">Primary key, cross section data id. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _crossSectionDataId)
		{
			return Delete(null, _crossSectionDataId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_crossSectionDataId">Primary key, cross section data id. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _crossSectionDataId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS key.
		///		FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS Description: 
		/// </summary>
		/// <param name="_crossSectionId">Foreign key to CROSS_SECTIONS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public TList<CrossSectionDatum> GetByCrossSectionId(System.Int32? _crossSectionId)
		{
			int count = -1;
			return GetByCrossSectionId(_crossSectionId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS key.
		///		FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_crossSectionId">Foreign key to CROSS_SECTIONS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		/// <remarks></remarks>
		public TList<CrossSectionDatum> GetByCrossSectionId(TransactionManager transactionManager, System.Int32? _crossSectionId)
		{
			int count = -1;
			return GetByCrossSectionId(transactionManager, _crossSectionId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS key.
		///		FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_crossSectionId">Foreign key to CROSS_SECTIONS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public TList<CrossSectionDatum> GetByCrossSectionId(TransactionManager transactionManager, System.Int32? _crossSectionId, int start, int pageLength)
		{
			int count = -1;
			return GetByCrossSectionId(transactionManager, _crossSectionId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS key.
		///		fkCrossSectionsDataCrossSections Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_crossSectionId">Foreign key to CROSS_SECTIONS</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public TList<CrossSectionDatum> GetByCrossSectionId(System.Int32? _crossSectionId, int start, int pageLength)
		{
			int count =  -1;
			return GetByCrossSectionId(null, _crossSectionId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS key.
		///		fkCrossSectionsDataCrossSections Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_crossSectionId">Foreign key to CROSS_SECTIONS</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public TList<CrossSectionDatum> GetByCrossSectionId(System.Int32? _crossSectionId, int start, int pageLength,out int count)
		{
			return GetByCrossSectionId(null, _crossSectionId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS key.
		///		FK_CROSS_SECTIONS_DATA_CROSS_SECTIONS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_crossSectionId">Foreign key to CROSS_SECTIONS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public abstract TList<CrossSectionDatum> GetByCrossSectionId(TransactionManager transactionManager, System.Int32? _crossSectionId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_STATUSES key.
		///		FK_CROSS_SECTIONS_DATA_STATUSES Description: 
		/// </summary>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public TList<CrossSectionDatum> GetByStatus(System.String _status)
		{
			int count = -1;
			return GetByStatus(_status, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_STATUSES key.
		///		FK_CROSS_SECTIONS_DATA_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		/// <remarks></remarks>
		public TList<CrossSectionDatum> GetByStatus(TransactionManager transactionManager, System.String _status)
		{
			int count = -1;
			return GetByStatus(transactionManager, _status, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_STATUSES key.
		///		FK_CROSS_SECTIONS_DATA_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public TList<CrossSectionDatum> GetByStatus(TransactionManager transactionManager, System.String _status, int start, int pageLength)
		{
			int count = -1;
			return GetByStatus(transactionManager, _status, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_STATUSES key.
		///		fkCrossSectionsDataStatuses Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public TList<CrossSectionDatum> GetByStatus(System.String _status, int start, int pageLength)
		{
			int count =  -1;
			return GetByStatus(null, _status, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_STATUSES key.
		///		fkCrossSectionsDataStatuses Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public TList<CrossSectionDatum> GetByStatus(System.String _status, int start, int pageLength,out int count)
		{
			return GetByStatus(null, _status, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_CROSS_SECTIONS_DATA_STATUSES key.
		///		FK_CROSS_SECTIONS_DATA_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.CrossSectionDatum objects.</returns>
		public abstract TList<CrossSectionDatum> GetByStatus(TransactionManager transactionManager, System.String _status, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override BesAsm.MasterData.Entities.CrossSectionDatum Get(TransactionManager transactionManager, BesAsm.MasterData.Entities.CrossSectionDatumKey key, int start, int pageLength)
		{
			return GetByCrossSectionDataId(transactionManager, key.CrossSectionDataId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_CROSS_SECTIONS_DATA index.
		/// </summary>
		/// <param name="_crossSectionDataId">Primary key, cross section data id</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.CrossSectionDatum GetByCrossSectionDataId(System.Int32 _crossSectionDataId)
		{
			int count = -1;
			return GetByCrossSectionDataId(null,_crossSectionDataId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_CROSS_SECTIONS_DATA index.
		/// </summary>
		/// <param name="_crossSectionDataId">Primary key, cross section data id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.CrossSectionDatum GetByCrossSectionDataId(System.Int32 _crossSectionDataId, int start, int pageLength)
		{
			int count = -1;
			return GetByCrossSectionDataId(null, _crossSectionDataId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_CROSS_SECTIONS_DATA index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_crossSectionDataId">Primary key, cross section data id</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.CrossSectionDatum GetByCrossSectionDataId(TransactionManager transactionManager, System.Int32 _crossSectionDataId)
		{
			int count = -1;
			return GetByCrossSectionDataId(transactionManager, _crossSectionDataId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_CROSS_SECTIONS_DATA index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_crossSectionDataId">Primary key, cross section data id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.CrossSectionDatum GetByCrossSectionDataId(TransactionManager transactionManager, System.Int32 _crossSectionDataId, int start, int pageLength)
		{
			int count = -1;
			return GetByCrossSectionDataId(transactionManager, _crossSectionDataId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_CROSS_SECTIONS_DATA index.
		/// </summary>
		/// <param name="_crossSectionDataId">Primary key, cross section data id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> class.</returns>
		public BesAsm.MasterData.Entities.CrossSectionDatum GetByCrossSectionDataId(System.Int32 _crossSectionDataId, int start, int pageLength, out int count)
		{
			return GetByCrossSectionDataId(null, _crossSectionDataId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_CROSS_SECTIONS_DATA index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_crossSectionDataId">Primary key, cross section data id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.CrossSectionDatum GetByCrossSectionDataId(TransactionManager transactionManager, System.Int32 _crossSectionDataId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;CrossSectionDatum&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;CrossSectionDatum&gt;"/></returns>
		public static TList<CrossSectionDatum> Fill(IDataReader reader, TList<CrossSectionDatum> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				BesAsm.MasterData.Entities.CrossSectionDatum c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("CrossSectionDatum")
					.Append("|").Append((System.Int32)reader[((int)CrossSectionDatumColumn.CrossSectionDataId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<CrossSectionDatum>(
					key.ToString(), // EntityTrackingKey
					"CrossSectionDatum",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new BesAsm.MasterData.Entities.CrossSectionDatum();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.CrossSectionDataId = (System.Int32)reader[((int)CrossSectionDatumColumn.CrossSectionDataId - 1)];
					c.OriginalCrossSectionDataId = c.CrossSectionDataId;
					c.CrossSectionId = (reader.IsDBNull(((int)CrossSectionDatumColumn.CrossSectionId - 1)))?null:(System.Int32?)reader[((int)CrossSectionDatumColumn.CrossSectionId - 1)];
					c.OrderIndex = (reader.IsDBNull(((int)CrossSectionDatumColumn.OrderIndex - 1)))?null:(System.Int32?)reader[((int)CrossSectionDatumColumn.OrderIndex - 1)];
					c.Station = (reader.IsDBNull(((int)CrossSectionDatumColumn.Station - 1)))?null:(System.Decimal?)reader[((int)CrossSectionDatumColumn.Station - 1)];
					c.Elevation = (reader.IsDBNull(((int)CrossSectionDatumColumn.Elevation - 1)))?null:(System.Decimal?)reader[((int)CrossSectionDatumColumn.Elevation - 1)];
					c.EditedBy = (System.String)reader[((int)CrossSectionDatumColumn.EditedBy - 1)];
					c.EditReason = (System.String)reader[((int)CrossSectionDatumColumn.EditReason - 1)];
					c.Status = (System.String)reader[((int)CrossSectionDatumColumn.Status - 1)];
					c.AppendDate = (System.DateTime)reader[((int)CrossSectionDatumColumn.AppendDate - 1)];
					c.EditDate = (reader.IsDBNull(((int)CrossSectionDatumColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)CrossSectionDatumColumn.EditDate - 1)];
					c.MstXsectionDatIdDeprecated = (reader.IsDBNull(((int)CrossSectionDatumColumn.MstXsectionDatIdDeprecated - 1)))?null:(System.Int32?)reader[((int)CrossSectionDatumColumn.MstXsectionDatIdDeprecated - 1)];
					c.MstXsectionsIdDeprecated = (reader.IsDBNull(((int)CrossSectionDatumColumn.MstXsectionsIdDeprecated - 1)))?null:(System.Int32?)reader[((int)CrossSectionDatumColumn.MstXsectionsIdDeprecated - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, BesAsm.MasterData.Entities.CrossSectionDatum entity)
		{
			if (!reader.Read()) return;
			
			entity.CrossSectionDataId = (System.Int32)reader[((int)CrossSectionDatumColumn.CrossSectionDataId - 1)];
			entity.OriginalCrossSectionDataId = (System.Int32)reader["cross_section_data_id"];
			entity.CrossSectionId = (reader.IsDBNull(((int)CrossSectionDatumColumn.CrossSectionId - 1)))?null:(System.Int32?)reader[((int)CrossSectionDatumColumn.CrossSectionId - 1)];
			entity.OrderIndex = (reader.IsDBNull(((int)CrossSectionDatumColumn.OrderIndex - 1)))?null:(System.Int32?)reader[((int)CrossSectionDatumColumn.OrderIndex - 1)];
			entity.Station = (reader.IsDBNull(((int)CrossSectionDatumColumn.Station - 1)))?null:(System.Decimal?)reader[((int)CrossSectionDatumColumn.Station - 1)];
			entity.Elevation = (reader.IsDBNull(((int)CrossSectionDatumColumn.Elevation - 1)))?null:(System.Decimal?)reader[((int)CrossSectionDatumColumn.Elevation - 1)];
			entity.EditedBy = (System.String)reader[((int)CrossSectionDatumColumn.EditedBy - 1)];
			entity.EditReason = (System.String)reader[((int)CrossSectionDatumColumn.EditReason - 1)];
			entity.Status = (System.String)reader[((int)CrossSectionDatumColumn.Status - 1)];
			entity.AppendDate = (System.DateTime)reader[((int)CrossSectionDatumColumn.AppendDate - 1)];
			entity.EditDate = (reader.IsDBNull(((int)CrossSectionDatumColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)CrossSectionDatumColumn.EditDate - 1)];
			entity.MstXsectionDatIdDeprecated = (reader.IsDBNull(((int)CrossSectionDatumColumn.MstXsectionDatIdDeprecated - 1)))?null:(System.Int32?)reader[((int)CrossSectionDatumColumn.MstXsectionDatIdDeprecated - 1)];
			entity.MstXsectionsIdDeprecated = (reader.IsDBNull(((int)CrossSectionDatumColumn.MstXsectionsIdDeprecated - 1)))?null:(System.Int32?)reader[((int)CrossSectionDatumColumn.MstXsectionsIdDeprecated - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, BesAsm.MasterData.Entities.CrossSectionDatum entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.CrossSectionDataId = (System.Int32)dataRow["cross_section_data_id"];
			entity.OriginalCrossSectionDataId = (System.Int32)dataRow["cross_section_data_id"];
			entity.CrossSectionId = Convert.IsDBNull(dataRow["cross_section_id"]) ? null : (System.Int32?)dataRow["cross_section_id"];
			entity.OrderIndex = Convert.IsDBNull(dataRow["order_index"]) ? null : (System.Int32?)dataRow["order_index"];
			entity.Station = Convert.IsDBNull(dataRow["station"]) ? null : (System.Decimal?)dataRow["station"];
			entity.Elevation = Convert.IsDBNull(dataRow["elevation"]) ? null : (System.Decimal?)dataRow["elevation"];
			entity.EditedBy = (System.String)dataRow["edited_by"];
			entity.EditReason = (System.String)dataRow["edit_reason"];
			entity.Status = (System.String)dataRow["status"];
			entity.AppendDate = (System.DateTime)dataRow["append_date"];
			entity.EditDate = Convert.IsDBNull(dataRow["edit_date"]) ? null : (System.DateTime?)dataRow["edit_date"];
			entity.MstXsectionDatIdDeprecated = Convert.IsDBNull(dataRow["mst_xsection_dat_id_deprecated"]) ? null : (System.Int32?)dataRow["mst_xsection_dat_id_deprecated"];
			entity.MstXsectionsIdDeprecated = Convert.IsDBNull(dataRow["mst_xsections_id_deprecated"]) ? null : (System.Int32?)dataRow["mst_xsections_id_deprecated"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.CrossSectionDatum"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.CrossSectionDatum Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, BesAsm.MasterData.Entities.CrossSectionDatum entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region CrossSectionIdSource	
			if (CanDeepLoad(entity, "CrossSection|CrossSectionIdSource", deepLoadType, innerList) 
				&& entity.CrossSectionIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.CrossSectionId ?? (int)0);
				CrossSection tmpEntity = EntityManager.LocateEntity<CrossSection>(EntityLocator.ConstructKeyFromPkItems(typeof(CrossSection), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.CrossSectionIdSource = tmpEntity;
				else
					entity.CrossSectionIdSource = DataRepository.CrossSectionProvider.GetByCrossSectionId(transactionManager, (entity.CrossSectionId ?? (int)0));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CrossSectionIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.CrossSectionIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.CrossSectionProvider.DeepLoad(transactionManager, entity.CrossSectionIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion CrossSectionIdSource

			#region StatusSource	
			if (CanDeepLoad(entity, "Status|StatusSource", deepLoadType, innerList) 
				&& entity.StatusSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.Status;
				Status tmpEntity = EntityManager.LocateEntity<Status>(EntityLocator.ConstructKeyFromPkItems(typeof(Status), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.StatusSource = tmpEntity;
				else
					entity.StatusSource = DataRepository.StatusProvider.GetByStatusId(transactionManager, entity.Status);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'StatusSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.StatusSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.StatusProvider.DeepLoad(transactionManager, entity.StatusSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion StatusSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the BesAsm.MasterData.Entities.CrossSectionDatum object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">BesAsm.MasterData.Entities.CrossSectionDatum instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.CrossSectionDatum Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, BesAsm.MasterData.Entities.CrossSectionDatum entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region CrossSectionIdSource
			if (CanDeepSave(entity, "CrossSection|CrossSectionIdSource", deepSaveType, innerList) 
				&& entity.CrossSectionIdSource != null)
			{
				DataRepository.CrossSectionProvider.Save(transactionManager, entity.CrossSectionIdSource);
				entity.CrossSectionId = entity.CrossSectionIdSource.CrossSectionId;
			}
			#endregion 
			
			#region StatusSource
			if (CanDeepSave(entity, "Status|StatusSource", deepSaveType, innerList) 
				&& entity.StatusSource != null)
			{
				DataRepository.StatusProvider.Save(transactionManager, entity.StatusSource);
				entity.Status = entity.StatusSource.StatusId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region CrossSectionDatumChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>BesAsm.MasterData.Entities.CrossSectionDatum</c>
	///</summary>
	public enum CrossSectionDatumChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>CrossSection</c> at CrossSectionIdSource
		///</summary>
		[ChildEntityType(typeof(CrossSection))]
		CrossSection,
			
		///<summary>
		/// Composite Property for <c>Status</c> at StatusSource
		///</summary>
		[ChildEntityType(typeof(Status))]
		Status,
		}
	
	#endregion CrossSectionDatumChildEntityTypes
	
	#region CrossSectionDatumFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;CrossSectionDatumColumn&gt;"/> class
	/// that is used exclusively with a <see cref="CrossSectionDatum"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class CrossSectionDatumFilterBuilder : SqlFilterBuilder<CrossSectionDatumColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the CrossSectionDatumFilterBuilder class.
		/// </summary>
		public CrossSectionDatumFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the CrossSectionDatumFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public CrossSectionDatumFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the CrossSectionDatumFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public CrossSectionDatumFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion CrossSectionDatumFilterBuilder
	
	#region CrossSectionDatumParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;CrossSectionDatumColumn&gt;"/> class
	/// that is used exclusively with a <see cref="CrossSectionDatum"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class CrossSectionDatumParameterBuilder : ParameterizedSqlFilterBuilder<CrossSectionDatumColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the CrossSectionDatumParameterBuilder class.
		/// </summary>
		public CrossSectionDatumParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the CrossSectionDatumParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public CrossSectionDatumParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the CrossSectionDatumParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public CrossSectionDatumParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion CrossSectionDatumParameterBuilder
	
	#region CrossSectionDatumSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;CrossSectionDatumColumn&gt;"/> class
	/// that is used exclusively with a <see cref="CrossSectionDatum"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class CrossSectionDatumSortBuilder : SqlSortBuilder<CrossSectionDatumColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the CrossSectionDatumSqlSortBuilder class.
		/// </summary>
		public CrossSectionDatumSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion CrossSectionDatumSortBuilder
	
} // end namespace
